import Vue from 'vue'
import VueRouter from 'vue-router'
import {routerMode} from '@/config/env'
import store from '@/store/index'

Vue.use(VueRouter);

let routes = [
    {
        path: '/',
        name: 'index',
        component: () => import('@/view/index'),
        beforeEnter: function (to, from, next) {
            try {
                document.getElementById('paper').className = 'back_out';
                setTimeout(() => {
                    next()
                }, 1500)
            } catch (e) {
                next()
            }

        }
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/view/login')
    },
    {path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('@/view/notfound')},
]
const router = new VueRouter({
    mode: routerMode,
    routes
})
//路由守卫
router.beforeEach((to, from, next) => { // 全局路由守卫
    if (to.path === '/login')return next();
    store.state.userId?next():next({path:"/login"});
})
export {router}
